package com.client.view;

import com.client.bean.UserInfo;
import com.client.db.UserDbOper;
import com.sun.awt.AWTUtilities;

import javax.swing.*;
import java.awt.*;

/**
 * Created by Administrator on 2016/12/19.
 */
public class TipView extends JFrame {
	JLabel lblTip;

	public TipView(UserInfo self) {
		setUndecorated(true);
		setSize(300,150);
		int width = getToolkit().getScreenSize().width;
		int height = getToolkit().getScreenSize().height - 30;
		width = width - this.getWidth();

		Container con = getContentPane();
		String s = self.getNicknName() + "[" + self.getCode() + "]上线啦";
		lblTip = new JLabel(s , new ImageIcon(self.getFace()) , JLabel.CENTER);
		lblTip.setBackground(Color.PINK);
		lblTip.setOpaque(true);
		con.add(lblTip);
		setVisible(true);
		setAlwaysOnTop(true);

		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

		try {
			for (int i = 0; i < 100; i++) {
				setLocation(width , height - (int)(i*1.5));
				Thread.sleep(50);
			}

			/**
			 * 设置窗口的透明度
			 */
			for (int i = 100; i >= 1; i--) {
				AWTUtilities.setWindowOpacity(this , 0.01f*i);
				Thread.sleep(50);
			}
			dispose();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		UserInfo userInfo = new UserInfo();
		userInfo.setCode(812962524);
		userInfo.setPassword("123456");
		userInfo = new UserDbOper().login(userInfo);
		new TipView(userInfo);
	}
}
